using System;
using System.Collections.Generic;
using System.Text;
using System.Xml.Serialization;

using MVPlan.Engine;
using MVPlan.Engine.Gases;

namespace MVPlan.Engine.Segment
{
    /// <summary>
    /// Describes a dive segment, a specialisation of AbstractSegment.
    /// </summary>
    [Serializable]
    [XmlInclude(typeof(SegmentAbstract))]
	public class SegmentDive : SegmentAbstract
    {
        #region Constructors

        /// <summary>
        /// Constructor for objects of class SegmentDive.
        /// </summary>
		/// <param name="depth">Depth of segment</param>
		/// <param name="time">Time of segment</param>
		/// <param name="gas">Gas object for segment</param>
		/// <param name="setpoint">Setpoint for segment, or 0 for open circuit</param>
		public SegmentDive(double depth, double time, Gas gas, double setpoint)
		{
			base.depth = depth;
			base.gas = gas;
			base.setpoint = setpoint;
			base.type = SegmentType.CONST;
			base.time = time;
		}
		
		/// <summary>
        /// Empty constructor for DiveSegment.
        /// </summary>
		public SegmentDive()
		{
			// Make sure it has at least air as a gas
			base.gas = new Gas(0.21, 0, 66.0);
        }

        #endregion

        #region Methods

        /// <summary>
        /// Override GasUsed() to determine the gas used in this segment.
        /// </summary>
		/// <returns> GasUsed in litres (cuft)</returns>
		public override double GasUsed()
		{
			if (setpoint > 0)
				return (0);

			double p; // pressure

			p = (depth + Prefs.Current.PAmb) / Prefs.Current.PConversion; // Convert to pressure (atm);
			
            return (p * time * Prefs.Current.RMVDive);
		}
		
        #endregion
    }
}
